package com.itheima.sfbx.insurance.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.itheima.sfbx.framework.commons.basic.ResponseResult;
import com.itheima.sfbx.framework.commons.utils.ResponseResultBuild;
import com.itheima.sfbx.insurance.dto.SafeguardVO;
import com.itheima.sfbx.insurance.service.impl.SafeguardServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "保障项")
@RestController
@RequestMapping("/safeguard")
public class SafeguardController {
    @Autowired
    private SafeguardServiceImpl safeguardService;

    /**
     * 分页查询保障项
     * @param safeguardVO 保障项VO对象
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return Page<SafeguardVO>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    @ApiOperation(value = "保障项分页查询",notes = "保障项分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardName","safeguardVO.safeguardType","safeguardVO.safeguardState","safeguardVO.safeguardPrice","safeguardVO.safeguardDesc","safeguardVO.safeguardImg","safeguardVO.safeguardSortNo"})
    public ResponseResult<Page<SafeguardVO>> findSafeguardVOPage(
            @RequestBody SafeguardVO safeguardVO,
            @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize) {
        Page<SafeguardVO> safeguardVOPage = safeguardService.findPage(safeguardVO, pageNum, pageSize);
        return ResponseResultBuild.successBuild(safeguardVOPage);
    }

    /**
     * 保存保障项
     * @param safeguardVO 保障项VO对象
     * @return SafeguardVO
     */
    @PutMapping
    @ApiOperation(value = "保存保障项",notes = "添加保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardName","safeguardVO.safeguardType","safeguardVO.safeguardState","safeguardVO.safeguardPrice","safeguardVO.safeguardDesc","safeguardVO.safeguardImg","safeguardVO.safeguardSortNo"})
    public ResponseResult<SafeguardVO> createSafeguard(@RequestBody SafeguardVO safeguardVO) {
        SafeguardVO result = safeguardService.save(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 修改保障项
     * @param safeguardVO 保障项VO对象
     * @return Boolean
     */
    @PatchMapping
    @ApiOperation(value = "修改保障项",notes = "修改保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.id","safeguardVO.safeguardKey","safeguardVO.safeguardName","safeguardVO.safeguardType","safeguardVO.safeguardState","safeguardVO.safeguardPrice","safeguardVO.safeguardDesc","safeguardVO.safeguardImg","safeguardVO.safeguardSortNo"})
    public ResponseResult<Boolean> updateSafeguard(@RequestBody SafeguardVO safeguardVO) {
        Boolean result = safeguardService.update(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 删除保障项
     * @param safeguardVO 保障项VO对象
     * @return Boolean
     */
    @DeleteMapping
    @ApiOperation(value = "删除保障项",notes = "删除保障项")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.checkedIds"})
    public ResponseResult<Boolean> deleteSafeguard(@RequestBody SafeguardVO safeguardVO) {
        Boolean result = safeguardService.delete(safeguardVO.getCheckedIds());
        return ResponseResultBuild.successBuild(result);
    }

    /**
     * 查询保障项列表
     * @param safeguardVO 保障项VO对象
     * @return List<SafeguardVO>
     */
    @PostMapping("list")
    @ApiOperation(value = "多条件查询保障项列表",notes = "多条件查询保障项列表")
    @ApiImplicitParam(name = "safeguardVO",value = "VO对象",required = true,dataType = "SafeguardVO")
    @ApiOperationSupport(includeParameters = {"safeguardVO.safeguardKey","safeguardVO.safeguardName","safeguardVO.safeguardType","safeguardVO.safeguardState","safeguardVO.safeguardPrice","safeguardVO.safeguardDesc","safeguardVO.safeguardImg","safeguardVO.safeguardSortNo"})
    public ResponseResult<List<SafeguardVO>> safeguardList(@RequestBody SafeguardVO safeguardVO) {
        List<SafeguardVO> result = safeguardService.findList(safeguardVO);
        return ResponseResultBuild.successBuild(result);
    }

}
